/**
 * 软件著作权：东方汇创
 *
 * 系统名称：  xxx项目
 *
 * 文件名称：  AuthorizeController.java
 *
 * 功能描述：  rm_authorizeController
 * 
 * 版本历史：
 * 
 * 2018-07-11   1.0.0版 （龙色波）（创建文件）
 */

package org.quickbundle.orgauth.rmauthorize.web;



import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.quickbundle.orgauth.rmauthorize.service.impl.RmAuthorizeService;
import org.quickbundle.orgauth.rmauthorize.util.IRmAuthorizeConstants;
import org.quickbundle.orgauth.rmauthorize.vo.RmAuthorizeVo;
import org.quickbundle.project.RmProjectHelper;
import org.quickbundle.tools.helper.RmSqlHelper;
import org.quickbundle.tools.helper.RmVoHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dfhc.ISystemConstant;
import com.dfhc.pub.concurrencycontrol.RequestConcurrentLockException;
import com.dfhc.pub.concurrencycontrol.RequestConcurrentRoute;
import com.dfhc.util.JspHelper;
import com.dfhc.util.StringHelper;

/**
 * rm_authorize Controller
 * 
 * @author 龙色波
 * @see 参见的类
 */
@Controller
@RequestMapping(value = "/rmauthorize")
public class AuthorizeController implements IRmAuthorizeConstants {

    @Autowired
    /**
     * rm_authorize服务
     */
    private RmAuthorizeService authorizeService;

    /**
     * 简单查询，分页显示，支持表单回写
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "")
    public String list(Model model, HttpServletRequest request) {
        return "/qb5activiti/rm/rmauthorize/listAuthorize";
    }
   
    /**
     * ajax 请求列表数据
     * @param model
     * @param request
     * @return
     * @throws IOException 
     */
    @RequestMapping(value = "ajaxList",  produces="application/json")
    @ResponseBody
    public Map<String,Object> ajaxList(Model model, HttpServletRequest request, HttpServletResponse response) throws IOException{
           Map<String,Object> dataMap=new HashMap<String,Object>();
           try{
		        //获取开始记录数
		        String startRow = request.getParameter(ISystemConstant.PAGE_START_KEY);
		        String rows=request.getParameter(ISystemConstant.PAGE_SIZE_KEY)==null?ISystemConstant.DEFAULT_PAGE_SIZE:request.getParameter(ISystemConstant.PAGE_SIZE_KEY);	        
		        int rowsInt=Integer.parseInt(rows);//页大小
		        if(StringHelper.isEmpty(startRow)){
		        	startRow="0";
		        }
		        int startRowInt = Integer.parseInt(startRow);
		        String  searchPara = getQueryCondition(request);  //从request中获得查询条件
		        int totalNum = authorizeService.getRecordCount(searchPara);
		        String orderStr = JspHelper.getOrderStr(request);  //得到排序信息
	        
	        	List<RmAuthorizeVo> beans = authorizeService.queryByCondition(searchPara, orderStr, startRowInt+1, rowsInt);  //按条件查询全部,带排序
	        	//翻译状态码
	        	/*if(beans!=null){
	        	for(RmAuthorizeVo bean:beans){
				//如果状态码字段有其他用途，请用扩展字段attribute1-attribute5代替
				bean.setIsAloneTable(RmGlobalReference.get(ISystemConstant.DICTIONARY_RM_YES_NOT, bean.getIsAloneTable()));
				bean.setSettiingOption(RmGlobalReference.get(ISystemConstant.DICTIONARY_RM_OPTION_TYPE, bean.getSettiingOption()));
	        	}
	        	}     */    
	        	dataMap.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        dataMap.put(ISystemConstant.PAGE_DRAW, request.getParameter(ISystemConstant.PAGE_DRAW));
	        	dataMap.put(ISystemConstant.RECORDS_TOTAL,totalNum);
		        dataMap.put(ISystemConstant.RECORDS_FILTERED, totalNum);
	        	dataMap.put(ISystemConstant.DATA, beans);
	        	return dataMap;
          }catch(RequestConcurrentLockException e){
        	  RmProjectHelper.logInf(StringHelper.exceptionToString(e));
        	  dataMap.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
        	  dataMap.put(ISystemConstant.AJAX_MESSAGE, e.getMessage());
        	  return dataMap;   
          }catch(Exception e){
        	  e.printStackTrace();
        	  RmProjectHelper.logInf(StringHelper.exceptionToString(e));
        	  dataMap.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
        	  dataMap.put(ISystemConstant.AJAX_MESSAGE, "查询失败!");
        	  return dataMap;
          }
    }
    
    /**
     * 从页面表单获取信息注入vo，并插入单条记录
     * @param request http请求对象
     * @param vo 值对象
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "insert", method = RequestMethod.POST, 
			consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> insert(HttpServletRequest request, @Valid RmAuthorizeVo vo) throws Exception {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
	        RmVoHelper.markCreateStamp(request,vo);  //打创建时间,IP戳
	        Map<String, Object> result = new HashMap<String, Object>();
	        try{
	        	//将自定义代码中的《和》，分别替换回<和>
	        	vo.setCustom_code(StringHelper.replaceAll(vo.getCustom_code(),"《", "<").toString());
	        	vo.setCustom_code(StringHelper.replaceAll(vo.getCustom_code(),"》", ">").toString());
		        authorizeService.insert(vo);
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        result.put(ISystemConstant.AJAX_MESSAGE, "新增rm_authorize成功!" );
	        }catch(Exception e){
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
		        result.put(ISystemConstant.AJAX_MESSAGE, "新增rm_authorize失败!");	        	
	        }
	        return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    
    /**
     * 从页面表单获取信息注入vo，并修改单条记录
     * @param request 请求对象
     * @param vo 值对象
     * @param errors Ajax错误对象
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "update", method = RequestMethod.POST, 
			consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> update(HttpServletRequest request, @Valid RmAuthorizeVo vo) throws Exception {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
        	RmVoHelper.markModifyStamp(request,vo);  //打修改时间,IP戳
	        Map<String, Object> result = new HashMap<String, Object>();
	        try{
	        	//将自定义代码中的《和》，分别替换回<和>
	        	vo.setCustom_code(StringHelper.replaceAll(vo.getCustom_code(),"《", "<").toString());
	        	vo.setCustom_code(StringHelper.replaceAll(vo.getCustom_code(),"》", ">").toString());
		        authorizeService.update(vo);
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        result.put(ISystemConstant.AJAX_MESSAGE, "更新rm_authorize成功!" );
	        }catch(Exception e){
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
		        result.put(ISystemConstant.AJAX_MESSAGE, "更新rm_authorize失败!");	        	
	        }
	        return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * 根据id获取单条记录
     * @param request 请求对象
     * @param vo 值对象
     * @param
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "get/{id}/{dateTime}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> get(@PathVariable("id") String id, HttpServletRequest request) throws Exception {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
        	RmAuthorizeVo bean = authorizeService.find(id);
	        Map<String, Object> result = new HashMap<String, Object>();
        	if(bean==null){
	            result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
        	    result.put(ISystemConstant.AJAX_MESSAGE, "记录没找到(id:"+id+")!");
	            return result;
        	}
        
	        result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
        	result.put(ISystemConstant.AJAX_BEAN, bean);
	        return result;			
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }    

   /**
     * 从页面的表单获取单条记录id并逻辑删除，如request.id为空则删除多条记录（request.ids）
     * @param request http请求对象
     * @param redirectAttributes 重定向属性
     * @return 返回列表页面
     */
/*    @RequestMapping(value = "logicDelete", method = RequestMethod.POST)
    public String deleteLogic(HttpServletRequest request, RedirectAttributes redirectAttributes) throws Exception {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
        	int deleteCount = 0;  //定义成功删除的记录数
	        String id = request.getParameter(REQUEST_ID);
        	if(id != null && id.length() > 0) {
	            deleteCount = authorizeService.deleteLogic(request,id);
        	} else {
	            String[] ids = RmJspHelper.getArrayFromRequest(request, REQUEST_IDS); //从request获取多条记录id
        	    if (ids != null && ids.length != 0) {
                	deleteCount += authorizeService.deleteLogic(request,ids);  //删除多条记录
	            }
        	}
	        redirectAttributes.addFlashAttribute("message", "删除成功: " + deleteCount);
        	return "redirect:/rmauthorize?"+ISystemConstant.RM_PARENT_CODE+"="+request.getParameter(ISystemConstant.RM_PARENT_CODE);
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }*/
    /**
     * 从页面的表单获取单条记录id，并察看这条记录的详细信息
     * @param id 待删除的id
     * @param model 模型
     * @request 请求对象
     * @return 返回详细信息页面
     */
    @RequestMapping(value = "details")
    public String detail(Model model, HttpServletRequest request) throws Exception {
    	//获取id
        String id = request.getParameter(REQUEST_ID);
        //根据id查询rm_authorize
        if(!StringHelper.isEmpty(id)){
  		RmAuthorizeVo vo = authorizeService.find(id);
  		model.addAttribute(REQUEST_BEAN, vo);
        }
	        return "/qb5activiti/rm/rmauthorize/details";
          
    }

   

    /**
     * 从request中获得查询条件
     * @param request http请求对象
     * @return 条件Map
     */
    public static String getQueryCondition(HttpServletRequest request) {
    	   String queryCondition = null;
    	    if(request.getAttribute(REQUEST_QUERY_CONDITION) != null) {  //如果request.getAttribute中有，就不取request.getParameter
    	        queryCondition = request.getAttribute(REQUEST_QUERY_CONDITION).toString();
    	    } else {
    			List<String> lQuery = new ArrayList<String>();
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".id", request.getParameter("id"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".bsKeyword", request.getParameter("bsKeyword"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".isAloneTable", request.getParameter("isAloneTable"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".authorizeResourceTableName", request.getParameter("authorizeResourceTableName"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".authorizeResrecTableName", request.getParameter("authorizeResrecTableName"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".authorizeAffixTableName", request.getParameter("authorizeAffixTableName"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".name", request.getParameter("name"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".settiingOption", request.getParameter("settiingOption"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".customCode", request.getParameter("customCode"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".description", request.getParameter("description"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".usableStatus", request.getParameter("usableStatus"), RmSqlHelper.TYPE_CHAR_LIKE));
    				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".constraint", request.getParameter("constraint"), RmSqlHelper.TYPE_CHAR_LIKE));
    			queryCondition = RmSqlHelper.appendQueryStr(lQuery.toArray(new String[0]));
    	    }
    	    return queryCondition;
    }
 
   /**
     * 详情页
     * 
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value="toDetail")
    public String toDetail(Model model, HttpServletRequest request) throws Exception{    	
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter("id"));

	    	String id=request.getParameter("id");
    	
	    	RmAuthorizeVo vo=authorizeService.find(id);
    	
    		model.addAttribute("authorizeVo", vo);
    	
	    	model.addAttribute("id", id);    
    		return "/qb5activiti/rm/rmauthorize/detailAuthorize";  
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }  	
    }
   /**
    * 前台导出通用业务表数据为xls,并下载
    * @throws Exception 
    *
    */
/*    @RequestMapping(value="exportXls"+ISystemConstant.SUFFIX_ACTION)
    public void frontExportXls(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception{	
          exportXls(model, request, response);
    }*/
   /**
    * 后台导出通用业务表数据为xls,并下载
    * @throws Exception 
    **/
/*   @RequestMapping(value="exportXls")
   public void backExportXls(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception{	
          exportXls(model, request, response);
   }*/
   /**
    * 导出xls公共方法
    * @param model
    * @param request
    * @param response
    * @throws UnsupportedEncodingException
    */
  /* private void exportXls(Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

	    	//获取排序
	    	String order = request.getParameter(ISystemConstant.PREDEFINED_ORDER);
	    	if(!StringHelper.isEmpty(order)){
			String order1 = new String(order.getBytes("ISO-8859-1"),"UTF-8");
		    	order = java.net.URLDecoder.decode(order1, "UTF-8");
	    	}
	    	Map<String, Object> searchPara = new HashMap<String,Object>();
	    	searchPara.put("delete_flag",ISystemConstant.DICTIONARY_RM_YES_NOT_0);
	    	List<RmAuthorizeVo> vos = authorizeService.queryByCondition(searchPara, order);    		
	    	String sheetName = request.getParameter(ISystemConstant.PREDEFINED_SHELL_NAME);
	    	if(StringHelper.isEmpty(sheetName)){
	    		sheetName = ISystemConstant.DEFAULT_SHELL_NAME;
	    	}
	    	LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String,String>();
	    	//获取删除的列名
	    	String deletes = request.getParameter(ISystemConstant.PREDEFINED_EXPORT_DELETE_COLUMNNAMES);
	    	List<String> deleteList =  new ArrayList<String>();
	    	if(!StringHelper.isEmpty(deletes)){
	    		deleteList = Arrays.asList(deletes.split(","));
	    	}
	    	//所有字段放入fieldMap
	    	fieldMap.put("id","ID");
	    	fieldMap.put("name","NAME");
	    	fieldMap.put("bsKeyword","BS_KEYWORD");
	    	fieldMap.put("isAloneTable","IS_ALONE_TABLE");
	    	fieldMap.put("authorizeResourceTableName","AUTHORIZE_RESOURCE_TABLE_NAME");
	    	fieldMap.put("authorizeResrecTableName","AUTHORIZE_RESREC_TABLE_NAME");
	    	fieldMap.put("authorizeAffixTableName","AUTHORIZE_AFFIX_TABLE_NAME");
	    	fieldMap.put("settiingOption","SETTIING_OPTION");
	    	fieldMap.put("customCode","CUSTOM_CODE");
	    	fieldMap.put("description","DESCRIPTION");
	    	fieldMap.put("usableStatus","USABLE_STATUS");
	    	fieldMap.put("modifyDate","MODIFY_DATE");
	    	fieldMap.put("modifyIp","MODIFY_IP");
	    	fieldMap.put("modifyUserId","MODIFY_USER_ID");
	    	fieldMap.put("constraint","CONSTRAINT");
	    	//删除无用字段
	    	for(String  propertyName:deleteList){
	    	    if(fieldMap.containsKey(propertyName)){
	    		fieldMap.remove(propertyName);
	    		continue;
	    	    }
	    	}
	    	
	    	//获取需要隐藏的列数组
	    	String hides = request.getParameter(ISystemConstant.PREDEFINED_EXPORT_HIDE_COLUMNNAMES);
	    	
	    	List<String> hideList =  new ArrayList<String>();
	    	if(!StringHelper.isEmpty(hides)){
	    		hideList = Arrays.asList(hides.split(","));
	    	}
	    	ExcelService.listToExcel(vos, fieldMap, hideList,sheetName, response);		
          }finally{
	    	//最后解锁
	    	RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }*/
    /**
     * 前台导入通用业务表数据为xls到数据库
     * @throws Exception 
     **/
   /* @RequestMapping(value="importXls"+ISystemConstant.SUFFIX_ACTION)
    public void frontImportXls(HttpServletRequest request, HttpServletResponse response) throws Exception{
    	importXls(request, response);
    }*/
    /**
     * 后台导入通用业务表数据为xls到数据库
     * @throws Exception 
     **/
/*    @RequestMapping(value="importXls")
    public void backImportXls(HttpServletRequest request, HttpServletResponse response) throws Exception{
    	importXls(request, response);
    }*/
    /**
     * 导入xls公共方法
     * @param request
     * @param response
     */
 /*   private void importXls(HttpServletRequest request, HttpServletResponse response) throws Exception {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

		   try {
			//获取上传文件xls
			List<MultipartFile> uploadFiles = FileOperateHelper.listMultipartFile(request);
			if(uploadFiles==null ||uploadFiles.isEmpty()){
				throw new PjException("缺少上传文件!");
			}	
			String sheetName = request.getParameter(ISystemConstant.PREDEFINED_SHELL_NAME);
			if(StringHelper.isEmpty(sheetName)){
		    		sheetName = ISystemConstant.DEFAULT_SHELL_NAME;
			}
			LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String,String>();
			String idCnName=null;//id中文名

			idCnName ="ID";
			fieldMap.put("ID","id");
			fieldMap.put("NAME","name");
			fieldMap.put("BS_KEYWORD","bsKeyword");
			fieldMap.put("IS_ALONE_TABLE","isAloneTable");
			fieldMap.put("AUTHORIZE_RESOURCE_TABLE_NAME","authorizeResourceTableName");
			fieldMap.put("AUTHORIZE_RESREC_TABLE_NAME","authorizeResrecTableName");
			fieldMap.put("AUTHORIZE_AFFIX_TABLE_NAME","authorizeAffixTableName");
			fieldMap.put("SETTIING_OPTION","settiingOption");
			fieldMap.put("CUSTOM_CODE","customCode");
			fieldMap.put("DESCRIPTION","description");
			fieldMap.put("USABLE_STATUS","usableStatus");
			fieldMap.put("MODIFY_DATE","modifyDate");
			fieldMap.put("MODIFY_IP","modifyIp");
			fieldMap.put("MODIFY_USER_ID","modifyUserId");
			fieldMap.put("CONSTRAINT","constraint");

			MultipartFile mfile = uploadFiles.get(0);
		    	
			List<RmAuthorizeVo> vos =null;
			InputStream inputStream = null;
			try{
				inputStream = mfile.getInputStream();
				if(!StringHelper.isEmpty(idCnName)){
					vos = ExcelService.excelToList(inputStream, sheetName, RmAuthorizeVo.class, fieldMap, new String[]{idCnName});
				}else{
					vos = ExcelService.excelToList(inputStream, sheetName, RmAuthorizeVo.class, fieldMap, new String[]{});
				}
			}finally{
				if(inputStream!=null){
					inputStream.close();
					inputStream = null;
				}
			}
			authorizeService.insertUpdateBatch(vos); 
			
		   } catch (Exception e) {
			e.printStackTrace();
			Map<String, Object> result = new HashMap<String, Object>();//
			result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
			String PjException = "com.dfhc.PjException:";
			result.put(ISystemConstant.AJAX_MESSAGE, e.getMessage().substring(e.getMessage().indexOf(PjException)+PjException.length()));
			response.setContentType("text/html;charset=utf-8");
			try {
				response.getWriter().print(JSONObject.toJSONString(result));
				response.getWriter().flush();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			return;
		   }
		   Map<String, Object> result = new HashMap<String, Object>();
		   result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		   result.put(ISystemConstant.AJAX_MESSAGE, "导入成功!");
		   response.setContentType("text/html;charset=utf-8");
		   try {
			response.getWriter().print(JSONObject.toJSONString(result));
			response.getWriter().flush();
		   } catch (IOException e) {
			e.printStackTrace();
		   }
          }finally{
		   //最后解锁
		   RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }*/
 /**
     * ajax逻辑删除
     * @param request http请求对象
     * @param redirectAttributes 重定向属性
     * @return 返回列表页面
    *//*
    @RequestMapping(value = "ajaxLogicDelete", method = RequestMethod.POST, 
    consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String, Object> ajaxLogicDelete(HttpServletRequest request) throws Exception {
          Map<String, Object> result = new HashMap<String, Object>();
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));


	        String id = request.getParameter(REQUEST_ID);
        	if(id != null && id.length() > 0) {
	            authorizeService.deleteLogic(request,id);
        	} else {
	            String[] ids = RmJspHelper.getArrayFromRequest(request, REQUEST_IDS); //从request获取多条记录id
        	    if (ids != null && ids.length != 0) {
                	authorizeService.deleteLogic(request,ids);  //删除多条记录
	            }
        	}
        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
        	result.put(ISystemConstant.AJAX_MESSAGE, "删除成功!");
        	return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }*/
    /**
     * 删除记录
     * @param request http请求对象
     * @return 返回列表页面
    */
    @RequestMapping(value = "delete", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String, Object> delete(HttpServletRequest request) throws Exception {
          boolean bLock = false;
          try{
        	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));        	
	        Map<String, Object> result = new HashMap<String, Object>();
	        try{
		        authorizeService.delete(request.getParameter(REQUEST_ID));
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        result.put(ISystemConstant.AJAX_MESSAGE, "删除rm_authorize成功!" );
	        }catch(Exception e){
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
		        result.put(ISystemConstant.AJAX_MESSAGE, "删除rm_authorize失败!");	        	
	        }
	        return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * 跳转到新增页面
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "addPage")
    public String addPage(Model model, HttpServletRequest request) {    	            
          return "/qb5activiti/rm/rmauthorize/addAuthorize";
    }
    /**
     * 跳转到编辑和查看页面
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "showPage")
    public String showPage(Model model, HttpServletRequest request) {
          //获取id
          String id = request.getParameter(REQUEST_ID);
          //根据id查询rm_authorize
          if(!StringHelper.isEmpty(id)){
    		RmAuthorizeVo vo = authorizeService.find(id);
    		model.addAttribute(REQUEST_BEAN, vo);
          }
          return "/qb5activiti/rm/rmauthorize/addAuthorize";
    }

}
